package com.example.myapplication.adapter.recyclerViewAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.myapplication.R;
import com.example.myapplication.entity.Mv;

import java.util.List;

public class MvAdapter extends RecyclerView.Adapter<MvAdapter.MvHolder> {
    private List<Mv.MvsBean> mvList ;
    private Context context;

    public void setData(List<Mv.MvsBean> mvList){
        this.mvList = mvList;
        notifyDataSetChanged();
    }
    public  MvAdapter(Context context){
         this.context = context;
    }

    @NonNull
    @Override
    public MvHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mv,parent,false);
        return new MvHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MvHolder holder, int position) {
        Mv.MvsBean mvsBean = mvList.get(position);
        holder.mv_desc.setText(mvsBean.getName());
        holder.mv_time.setText(mvsBean.getPublishTime());
        RoundedCorners roundedCorners= new RoundedCorners(30);
        RequestOptions options= RequestOptions.bitmapTransform(roundedCorners).override(300, 300);
        Glide.with(context).load(mvsBean.getImgurl())
                .centerCrop().apply(options).into(holder.mv_img);

    }

    @Override
    public int getItemCount() {
        return mvList==null?0:mvList.size();
    }

    class MvHolder extends RecyclerView.ViewHolder{
        ImageView mv_img;
        TextView mv_time;
        TextView mv_desc;
        public MvHolder(@NonNull View itemView) {
            super(itemView);
            mv_img=itemView.findViewById(R.id.mv_img);
            mv_time=itemView.findViewById(R.id.mv_time);
            mv_desc=itemView.findViewById(R.id.mv_desc);
        }
    }
}